package org.grumpybitz.sunrise;

import java.io.Serializable;
import java.util.Random;

import com.vaadin.data.util.BeanItemContainer;

public class CustomerContainer extends BeanItemContainer<Customer> implements
		Serializable {

	/**
	 *
	 */
	private static final long serialVersionUID = 4683707871079955717L;

	public static final Object[] NATURAL_COL_ORDER = new Object[] {
			"id", "name", "taxId" };
	public static final String[] COL_HEADERS_ENGLISH = new String[] {
		"ID", "Name", "Tax ID" };

	public static CustomerContainer createWithTestData() {
		try {
			CustomerContainer container = new CustomerContainer();
			Customer customer;
			Random random = new Random(0);
			int randomNumber;

			for (int i = 1; i <= 10; i++) {
				customer = new Customer();
				randomNumber = Math.abs(random.nextInt());
				customer.setId(randomNumber);
				customer.setName("Cliente " + randomNumber);
				customer.setTaxId("TAX_ID_" + randomNumber);
				container.addItem(customer);
			}

			return container;
		} catch (Exception e) {
			e.printStackTrace();
			throw new RuntimeException(e);
		}

	}

	public CustomerContainer() throws InstantiationException,
			IllegalAccessException {
		super(Customer.class);
	}
}